export function getTreeData(data) {
  for (let i = 0; i < data.length; i++) {
    if (data[i].children.length < 1) {
      // child若为空数组，则将child设为undefined
      data[i].children = undefined;
    } else {
      // child若不为空数组，则继续 递归调用 本方法
      getTreeData(data[i].children);
    }
  }
  return data;
}

export function isDefaultTime(time) {
  if (time.indexOf("1900") === -1) {
    return time
  } else {
    return ""
  }
}
export function wrapText(text, maxLength) {
  if (text) {
    if (text.length <= maxLength) {
      return text; // 如果字符串长度小于等于最大长度，则直接返回原字符串
    }

    let wrappedText = '';
    let currentLineLength = 0;

    for (let i = 0; i < text.length; i++) {
      wrappedText += text[i];
      currentLineLength++;

      if (currentLineLength === maxLength) {
        wrappedText += '<br>'; // 在达到最大长度时添加换行符
        currentLineLength = 0; // 重置当前行长度
      }
    }
    return wrappedText
  }
  return text;
}
// 通过文件下载url拿到对应的blob对象
export function getBlob(url) {
  return new Promise((resolve) => {
    const xhr = new XMLHttpRequest();
    xhr.open("GET", url, true);
    xhr.responseType = "blob";
    xhr.onload = () => {
      if (xhr.status === 200) {
        resolve(xhr.response);
      }
    };

    xhr.send();
  });
}
// 下载文件js模拟点击a标签进行下载
export function saveAs(blob, filename) {
  var link = document.createElement("a");
  link.href = window.URL.createObjectURL(blob);
  link.download = filename;
  link.click();
}
